var express = require('express');
var app = require('express')();
var fs = require('fs');


var router = express.Router();
const zlib = require('zlib');
const exportExcle = require('./fn/fn');
const bodyParser = require('body-parser');
const request = require('request');
const cache = require('memory-cache');
const apiService = require('../service/apiService');
const apiBase = require('../service/apiBase');

var IO = null;
router.io = function (io) {
	io.on('connection', (socket) => {
		socket.on('message', (data) => {
			// 操作data
			socket.emit('news', {
				type: 1,
				text: 'test',
				data: {
					"db101.CJ-WANO-HY1-1": 100,
					"db101.JT-LJSWDL": 196.9001234342
				}
			})
		})
	});
	IO = io;
	return io;
}

const {
	createWorker
} = require('tesseract.js');

const worker = createWorker();
var jsonParser = bodyParser.json({
	limit: '50mb'
});
const api = new apiService();
const base = new apiBase();
var urlencodedParser = bodyParser.urlencoded({
	extended: false,
	limit: '50mb',
	parameterLimit: 50000
});
/* GET home page. */
router.get('/', function (req, res, next) {
	res.render('pic/ldfbt', {
		title: 'Express'
	});
});
router.get('/ldtbt', function (req, res, next) {
	res.render('pic/ldtbt', {
		title: 'Express'
	});
});

/* GET home page. */
router.post('/getHtml', urlencodedParser, function (req, res, next) {
	let data = req['body'];
	let lineData = [];
	for (const key in data.data) {
		// const element = object[key];
		const arr = [key , data.data[key]]
		lineData.push(arr)
	}
	console.log(lineData)
	
	IO.sockets.emit('news', {
		type: data.type,
		text: data.text,
		lineData: lineData
	})
	res.json({
		name: 'lee'
	});
});

let EventEmitter = require('events');
let msg = new EventEmitter();



module.exports = router;